package com.alibaba.sdk.model.assembler.mapper;

import com.alibaba.sdk.model.entity.User;
import com.alibaba.sdk.model.output.OneUserResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 * @ author  Shawn(Shawn_0217@163.com)
 * @ date    2021/4/27 17:07
 * @ company Alibaba
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface UserMapper {

    UserMapper INSTANCE = Mappers.getMapper(UserMapper.class);

    /**
     * 实体类转DTO
     *
     * @param user
     * @return
     */
    @Mappings({
            // 忽略
            @Mapping(target = "id", ignore = true),
            @Mapping(source = "username", target = "userName"),
            @Mapping(source = "createTime", target = "addTime", dateFormat = "yyyy-MM-dd HH:mm:ss")
    })
    OneUserResponse fromEntity(User user);
}
